<?php
include_once "xAP-functions/webincludes.php";
include_once $config["modulefolder"]."/Triggers.php";


$id=intval($_POST["id"]); 
$delete=intval($_POST["delete"]); 
$name=dbesc($_POST["name"]);
$desc=dbesc($_POST["desc"]);
$channel=dbesc($_POST["channel"]);
$delay=intval($_POST["delay"]); 

if($id==0){
	$sql="insert into xAP_TV_Trigger (ProgName,ProgDesc,Delay,ChannelName) VALUES
	('".$name."','".$desc."','".$delay."','".$channel."')";

}
elseif($delete==1){
	$sql="delete from  xAP_TV_Trigger 
	where TriggerID=".$id;
}
else
{
	$sql="update xAP_TV_Trigger set
	ProgName='".$name."',
	ProgDesc='".$desc."',
	ChannelName='".$channel."',
	Delay='".$delay."'
	where TriggerID=".$id."
	";	
}
dbexec($sql);

//rebuild database to load in all the possible times for the alerts to go out
TriggersRegenerate();

header("Location:config_trigger.php");
?>